{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#本章需导入的模块\n",
    "import numpy as np\n",
    "from numpy import random\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "from mpl_toolkits.mplot3d import Axes3D\n",
    "import warnings\n",
    "warnings.filterwarnings(action = 'ignore')\n",
    "%matplotlib inline\n",
    "plt.rcParams['font.sans-serif']=['SimHei']  #解决中文显示乱码问题\n",
    "plt.rcParams['axes.unicode_minus']=False\n",
    "from sklearn.datasets import make_classification,make_circles,make_regression\n",
    "from sklearn.model_selection import train_test_split,KFold\n",
    "import sklearn.neural_network as net\n",
    "import sklearn.linear_model as LM\n",
    "from scipy.stats import multivariate_normal\n",
    "from sklearn.metrics import r2_score,mean_squared_error,classification_report\n",
    "from sklearn import svm\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "path='C:/Users/xuewe/《Python机器学习：数据建模与分析》代码/健康物联网/'\n",
    "#print(os.path.dirname(path)) 返回文件路径 \n",
    "#cwd=os.getcwd()  得到当前目录\n",
    "#os.path.join(dirname, filename)\n",
    "#os.walk(path) \n",
    "\n",
    "filenames=os.listdir(path=path)\n",
    "data=pd.DataFrame(columns=['TimeStamp', 'frontal', 'vertical', 'lateral', 'SensorID', 'RSSI','Phase', 'Frequency', 'Activity', 'ID', 'Gender'])\n",
    "i=1\n",
    "for filename in filenames:\n",
    "    tmp=pd.read_csv(path+filename)\n",
    "    tmp['ID']=i\n",
    "    tmp['Gender']=filename[-5]\n",
    "    i+=1\n",
    "    data=data.append(tmp)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEICAYAAACzliQjAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhc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LwYI5fxfYFtvtsHwqcA3zR9qG2X2P7HOB2qhPkimFWNZWqL3+l7X8EnrTdB9xAdS8k1qQWtdV+jyTtAiwDPk+5oftsMCb/GEbR3sBHgf9B1aJ/JpQkPY+qH/ANpbQZcEoZXucyz5VUx/TcsuwC4KKG1uhEqhuQTwDvKcscS3XpPtjP+nhD/ylUJ55zaK9lPNpeBZwoabWRHpIGW1QTqf6ArqXmx6+cqMYNdaXScIJcqeqDaROb5y3rkO3LtPrY+yXlCgKagqzJRBpu0ja9t22vXMu2a2O+mUt1Jf/Mh7BU/V9gV1KuhMrrC4B3Uv33yp8APiLpA1S/o1OB423/ny5v94hlnH4LkrakGt7mprqaaxGdkHQAcCLVUM1WJlJ1J1xbRpdcQ/W/0jb+/k2gui9wRblq+p7tgxreYxLVyW6R7a80vf9ZwEHAG2z/umnasVTfadE4lr/ROKo+7TF1Il2fykl0ehm2+ayS0I94FpO087MxuKJzCf2IiBrJjdyIiBpJ6EdE1EhCPyKiRhL6ERE1ktCPiKiR/w8Mnq1Ep7IZBgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEHCAYAAABCwJb2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAATYUlEQVR4nO3de5RmVX3m8e/TN227FSE0GKLQogQSIm2wwWZsYjNBLoNRJEaYiGaFEWJmJS5nHB0wsuIFL5lMHMVRZ1CiyDAaxNElS1SCl9jcRrqFBDKZFjWNAiKdwHCJyKX5zR9nV3gpqqurq+mqavb3s9a7+rz77LPfc6rP+7z77LPfqlQVkqQ+zJvtHZAkzRxDX5I6YuhL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zCS7JkxzjlDTG0Jekjjh7R5I6YuhLUkcMfUnqiKEvSR0x9CWpI/8feWBErVovCAIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "label=['坐在床上','坐在椅子上','躺在床上','行走']\n",
    "countskey=data['Activity'].value_counts().index\n",
    "plt.bar(np.unique(data['Activity']),data['Activity'].value_counts())\n",
    "plt.xticks([1,2,3,4],[label[countskey[0]-1],label[countskey[1]-1],label[countskey[2]-1],label[countskey[3]-1]])\n",
    "plt.title(\"老人的体位状态\")\n",
    "plt.show()\n",
    "data['ActivityN']=data['Activity'].map({3:0,1:0,2:1,4:1})\n",
    "plt.bar([1,2],data['ActivityN'].value_counts())\n",
    "plt.xticks([1,2],['安全体位','风险体位'])\n",
    "plt.title(\"老人的体位状态\")\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "测试误差=0.029143(poly)\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "           1       0.71      0.84      0.77       368\n",
      "           2       0.79      0.76      0.78       170\n",
      "           3       0.99      1.00      1.00      6147\n",
      "           4       0.90      0.17      0.28       109\n",
      "\n",
      "    accuracy                           0.97      6794\n",
      "   macro avg       0.85      0.69      0.71      6794\n",
      "weighted avg       0.97      0.97      0.97      6794\n",
      "\n",
      "测试误差=0.030321(rbf)\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "           1       0.71      0.77      0.74       368\n",
      "           2       0.82      0.71      0.76       170\n",
      "           3       0.99      1.00      0.99      6147\n",
      "           4       0.94      0.41      0.57       109\n",
      "\n",
      "    accuracy                           0.97      6794\n",
      "   macro avg       0.86      0.72      0.77      6794\n",
      "weighted avg       0.97      0.97      0.97      6794\n",
      "\n"
     ]
    }
   ],
   "source": [
    "Y=data['Activity'].astype(int)\n",
    "X=data[['frontal', 'vertical', 'lateral', 'RSSI']]\n",
    "X_train, X_test, Y_train, Y_test = train_test_split(X,Y,train_size=0.70, random_state=1)\n",
    "for ker in ['poly','rbf']:\n",
    "    modelSVC=svm.SVC(kernel=ker,random_state=123) \n",
    "    modelSVC.fit(X_train,Y_train)\n",
    "    print(\"测试误差=%f(%s)\"%(1-modelSVC.score(X_test,Y_test),ker))\n",
    "    print(classification_report(Y_test,modelSVC.predict(X_test)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练误差=0.020565\n",
      "测试误差=0.022078\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.98      0.99      0.99      6515\n",
      "           1       0.81      0.61      0.69       279\n",
      "\n",
      "    accuracy                           0.98      6794\n",
      "   macro avg       0.90      0.80      0.84      6794\n",
      "weighted avg       0.98      0.98      0.98      6794\n",
      "\n"
     ]
    }
   ],
   "source": [
    "Y=data['ActivityN'].astype(int)\n",
    "X=data[['frontal', 'vertical', 'lateral', 'RSSI']]\n",
    "X_train, X_test, Y_train, Y_test = train_test_split(X,Y,train_size=0.70, random_state=1)\n",
    "modelSVC=svm.SVC(kernel='rbf',random_state=123) \n",
    "modelSVC.fit(X_train,Y_train)\n",
    "print(\"训练误差=%f\"%(1-modelSVC.score(X_train,Y_train)))\n",
    "print(\"测试误差=%f\"%(1-modelSVC.score(X_test,Y_test)))\n",
    "print(classification_report(Y_test,modelSVC.predict(X_test)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练误差=0.024277\n",
      "部分报告:\n",
      "               precision    recall  f1-score   support\n",
      "\n",
      "           0       1.00      0.95      0.98      6515\n",
      "           1       0.48      1.00      0.65       279\n",
      "\n",
      "    accuracy                           0.95      6794\n",
      "   macro avg       0.74      0.98      0.81      6794\n",
      "weighted avg       0.98      0.95      0.96      6794\n",
      "\n"
     ]
    }
   ],
   "source": [
    "tmp=data.loc[data['ActivityN']==0,]\n",
    "random.seed(123)\n",
    "ID=random.choice(tmp.shape[0],size=data['ActivityN'].value_counts()[1],replace=False)\n",
    "NewData=tmp.iloc[ID,].append(data.loc[data['ActivityN']==1,])\n",
    "Y0=NewData['ActivityN'].astype(int)\n",
    "X0=NewData[['frontal', 'vertical', 'lateral', 'RSSI']]\n",
    "modelSVC=svm.SVC(kernel='rbf',random_state=123) \n",
    "modelSVC.fit(X0,Y0)\n",
    "print(\"训练误差=%f\"%(1-modelSVC.score(X0,Y0)))\n",
    "print(\"部分报告:\\n\",classification_report(Y_test,modelSVC.predict(X_test)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "总报告:\n",
      "               precision    recall  f1-score   support\n",
      "\n",
      "           0       1.00      0.95      0.98     21781\n",
      "           1       0.45      1.00      0.62       865\n",
      "\n",
      "    accuracy                           0.95     22646\n",
      "   macro avg       0.73      0.98      0.80     22646\n",
      "weighted avg       0.98      0.95      0.96     22646\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(\"总报告:\\n\",classification_report(Y,modelSVC.predict(X)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
